﻿<Page
    x:Name="PageRoot"
    x:Class="IntegrationExample.ContactPickerPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:IntegrationExample"
    xmlns:common="using:IntegrationExample.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:ExtensionType="FileOpenPicker">

    <Page.Resources>
        <CollectionViewSource x:Name="ContactsViewSource" 
                              Source="{Binding ContactGroups}"
                              IsSourceGrouped="True"
                              ItemsPath="Items"/>
        <DataTemplate x:Key="ContactItemTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid Grid.Column="0" Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" Margin="10">
                    <Image Source="{Binding Thumbnail, Converter={StaticResource ThumbnailValueConverter}}" 
                                       Width="100" Height="100"
                                       HorizontalAlignment="Center" VerticalAlignment="Center" 
                                       Stretch="Uniform"/>
                </Grid>
                <StackPanel Grid.Column="1" Width="180" Margin="0,10,10,10">
                    <TextBlock Text="{Binding DisplayName}" TextWrapping="NoWrap" Style="{StaticResource BodyTextBlockStyle}"/>
                    <TextBlock Text="{Binding Converter={StaticResource ContactEmailSelectionValueConverter}}"
                               Foreground="{ThemeResource ApplicationSecondaryForegroundThemeBrush}" 
                               Style="{StaticResource BodyTextBlockStyle}"/>
                    <TextBlock Text="{Binding Converter={StaticResource ContactPhoneSelectionValueConverter}}"
                               Foreground="{ThemeResource ApplicationSecondaryForegroundThemeBrush}" 
                               Style="{StaticResource BodyTextBlockStyle}"/>

                </StackPanel>
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the command area
        * Row 1 contains the rest of the page layout
    -->
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="80"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Command area -->
        <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="120,20,120,30">
        </StackPanel>

        <!-- Horizontal scrolling grid of files fills the remainder -->
        <GridView x:Name="ContactGridView"
                  AutomationProperties.AutomationId="ContactGridView"
                  AutomationProperties.Name="Contacts"
                  Grid.Row="0" Grid.RowSpan="2"
                  ItemsSource="{Binding Source={StaticResource ContactsViewSource}}"
                  ItemTemplate="{StaticResource ContactItemTemplate}"
                  SelectionMode="Multiple"
                  SelectedItem="{Binding SelectedContact, Mode=TwoWay}"
                  SelectionChanged="HandleSelectedContactChanged"
                  Padding="116,76,116,20" 
                  Visibility="Visible"/>
    </Grid>
</Page>
